package  
{
	import adobe.utils.CustomActions;
	import flash.display.MovieClip;
	import flash.display.Stage;
	import flash.events.Event;
	import flash.events.KeyboardEvent;
	import flash.events.MouseEvent;
	import flash.media.Sound;
	import flash.media.SoundChannel;
	import flash.net.URLRequest;
	import Levels.Level;
	import Levels.Level1;
	import Levels.Level2;
	import Objetos.Heroi;
	import Objetos.Inimigo;
	import Objetos.Tiro;
	/**
	 * ...
	 * @author Jen
	 */
	public class Main extends MovieClip
	{
		
		private var MC_heroi				:Heroi;
		private var MC_inimigo				:Inimigo;
		public var MC_tela					:MovieClip;	
		public var MC_play					:MovieClip;
		//public var MC_gOver					:MovieClip;
		
		private var ST_levelState			:String;
		public static var LV_faseatual		:Level;
		public static var LV_fase1			:Level1;
		public static var LV_fase2			:Level2;
		
		protected var SD_music				:Sound = new Sound(new URLRequest("metallica_enter_sandman_lullaby.mp3"));
		protected var SC					:SoundChannel = SD_music.play();
		protected var BO_tocando			:Boolean = true;
		protected var NB_posicaoM			:Number = 0;
		
		private static var _instance		:Main = null;		
		
		public static function getInstance():Main
		{
			return _instance;
		}
		
		public static function getStage():Stage
		{
			return getInstance().stage;
		}
		
		
		public function Main() 
		{
<<<<<<< .mine
			MC_play = new Play();
			MC_play.x = stage.stageWidth/2;
			MC_play.y = stage.stageHeight/2;
			addChild(MC_play);
=======
			MC_play = new Play();
			MC_play.x = stage.stageWidth/2;
			MC_play.y = stage.stageHeight/2;
			addChild(MC_play);
						
			MC_play.addEventListener(MouseEvent.CLICK, comecar, false, 0, true);
>>>>>>> .r9
			
			MC_play.addEventListener(MouseEvent.CLICK, comecar, false, 0, true);
			
			_instance = this;
			
<<<<<<< .mine
=======
			//iniciarJogo();	
>>>>>>> .r9
		}
		
		public function comecar(e:MouseEvent):void
		{
<<<<<<< .mine
			removeChild(MC_play);
			MC_play = null;
			removeEventListener(MouseEvent.CLICK, comecar);
			
			addEventListener(MouseEvent.CLICK, tocarMusica, false, 0, true);
			addEventListener(MouseEvent.MOUSE_WHEEL, pararMusica, false, 0, true);
			
			iniciarJogo();
=======
			removeChild(MC_play);
			MC_play = null;
			removeEventListener(MouseEvent.CLICK, comecar);
						
			addEventListener(MouseEvent.CLICK, tocarMusica, false, 0, true);
			addEventListener(MouseEvent.MOUSE_WHEEL, pararMusica, false, 0, true);
			
			iniciarJogo();
>>>>>>> .r9
		}

		public function removerFase():void
		{
			removeChild(MC_tela);
			MC_tela = null;
			
			MC_tela = new MovieClip();
			addChild(MC_tela);
		}
		
		public function criarFase(nome_da_fase:String):void
		{	
			ST_levelState = nome_da_fase;
			switch (ST_levelState)
			{
				case "Level1":
					LV_fase1 = new Level1;
					LV_faseatual = LV_fase1;
					break;
					
				case "Level2":
					LV_fase2 = new Level2;
					LV_faseatual = LV_fase2;
					break;
			}
			desenharTela();
		}
		
		public function iniciarJogo():void
		{
			MC_tela = new MovieClip;
			addChild(MC_tela);
			
			ST_levelState = "Level1";
			LV_fase1 = new Level1();
			LV_faseatual = LV_fase1;
			
			addEventListener(Event.ENTER_FRAME, update, false, 0, true);
		
			
			desenharTela();
		}
		
		
		public function desenharTela():void
		{
			switch (ST_levelState)
			{
				case "Level1":
					LV_fase1.desenharTela();
					LV_fase1.desenharArray();
					break;
					
				case "Level2":
					LV_fase2.desenharTela2();
					LV_fase2.desenharArray2();
					break;
			}

		}
		
		public 	function update (e:Event):void
		{
			switch (ST_levelState)
			{
				case "Level1":
					LV_fase1.update();
					break;
					
				case "Level2":
					LV_fase2.update();
					break;
			}	
		}
		
		public function pararMusica(e:Event):void
		{
			if (SC != null)
			{
				SC.stop();
				NB_posicaoM = 0;
				BO_tocando = false;
			}
		}
		
		public function tocarMusica(e:Event):void
		{
			if (!BO_tocando)
			{
				SC = SD_music.play(NB_posicaoM);
				BO_tocando = true;
			}
		}
		
		
/*		public function gameOver():void;
		{
			removeChild(MC_tela);
			MC_tela = null;
			
			MC_gOver = new gOver();
			MC_gOver.x = 0;
			MC_gOver.y = -264;
			addChild(MC_gOver);
			
			MC_play = new Play();
			MC_play.x = stage.stageWidth/2;
			MC_play.y = stage.stageHeight/2;
			addChild(MC_play);
			
			MC_play.addEventListener(MouseEvent.CLICK, comecar, false, 0, true);		
			
		}*/
	}
}